package com.klhappy.houyuan.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;

import com.klhappy.houyuan.R;
import com.klhappy.houyuan.adapter.AllBaseAdapter;
import com.klhappy.houyuan.adapter.ItemAdapter;
import com.klhappy.houyuan.bean.BaseJsonBean;
import com.klhappy.houyuan.bean.GoodsAllBean;
import com.klhappy.houyuan.constant.UrlConstant;
import com.klhappy.houyuan.interfaces.CallBackInterModle;
import com.klhappy.houyuan.modle.DingDanModle;
import com.klhappy.houyuan.view.AbsActivity;
import com.klhappy.houyuan.view.UnfoldedListView;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by MrPu on 15/12/27.
 */
public class SendDetialActicity extends AbsActivity implements CallBackInterModle{
    @InjectView(R.id.title)
    TextView title;
    @InjectView(R.id.tv_time)
    TextView tv_time;
    @InjectView(R.id.tv_sum)
    TextView tv_sum;
    @InjectView(R.id.tv_amount)
    TextView tv_amount;
    @InjectView(R.id.lv_content)
    UnfoldedListView lv_content;

    @OnClick(R.id.click_ra)
    public void click_ra() {
        finish();
    }

    @OnClick(R.id.btn_look)
    public void btn_look() {
        modle.setDan(or_id + "");
        showDialog("下单中...");
    }

    private ArrayList<GoodsAllBean> itemList;
    private String or_id;
    private DingDanModle modle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_send_detail);
        ButterKnife.inject(this);
        title.setText("订单详情");

        modle = new DingDanModle(this);
        modle.setCallBackInterModle(this);
        itemList = (ArrayList) this.getIntent().getSerializableExtra("order");
        or_id = (String) getIntent().getSerializableExtra("or_id");

        tv_time.setText(itemList.get(0).getTime());
        tv_sum.setText("共" + itemList.size() + "样商品");
        float acount = 0;
        for (int i = 0; i < itemList.size(); i ++){
            acount = acount + Float.parseFloat(itemList.get(i).getPrice())*Integer.parseInt(itemList.get(i).getCount());
        }
        tv_amount.setText("合计:  ￥" + acount);
        lv_content.setAdapter(new AllBaseAdapter(this, itemList));
        lv_content.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(SendDetialActicity.this, XiangqingActivity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("goodId", itemList.get(position).getId() + "");
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
    }

    @Override
    public void CallBackFromModle(String url, BaseJsonBean o) {
        if (url.equals(UrlConstant.REBUILD_URL)){
            showToastx(o.getMsg());
            closeDialog();
        }
    }
}
